package com.itany.nmms.util;

import com.itany.nmms.exception.MD5ErrorException;
import sun.misc.BASE64Encoder;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Author:shixiaojun@itany.com
 * Date:2022/5/24 10:22
 * Version:1.0-SNAPSHOT
 * Description:
 */
public class MD5Util {

    public static String md5(String s){
        try {
            MessageDigest md = MessageDigest.getInstance("md5");
            byte[] b = md.digest(s.getBytes());
            BASE64Encoder encoder = new BASE64Encoder();
            return encoder.encode(b);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            throw new MD5ErrorException("MD5加密出错");
        }

    }

}
